package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车相关接口")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result<String> add(@RequestBody ShoppingCartDTO dto){
        log.info("添加购物车接收到的参数:{}",dto);
        shoppingCartService.add(dto);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List<ShoppingCart>> select(){
        List<ShoppingCart>list = shoppingCartService.select(BaseContext.getCurrentId());
        return Result.success(list);
    }
    @DeleteMapping("clean")
    public Result<String>clean(){
        shoppingCartService.cleam();
    return Result.success();
    }
}
